#include<iostream>
#include<mysql/mysql.h>
using namespace std;
int main()
{
  
   // cout<<mysql_get_client_version()<<endl;
   MYSQL* m=mysql_init(NULL);
   if(mysql_real_connect(m,"localhost","root","153426789a","mytest",0,NULL,0)) cout<<"连接上了"<<endl;//连接数据库
   else   cout<<"连接失败"<<endl;
   if(!mysql_set_character_set(m, "utf8")) cout<<"设置成功"<<endl;
   /*if(!mysql_query(m,"insert into score values(50,'找',88,66,77)"))cout<<"插入成功"<<endl;
   else cout<<"插入失败"<<endl;*/
   if(!mysql_query(m,"select  * from score"))cout<<"查找成功"<<endl;
   else cout<<"查找失败"<<endl;
   MYSQL_RES* res=mysql_store_result(m);//处理返回的结果
   int r=mysql_num_rows(res);
   int f=mysql_num_fields(res);
   //cout<<"行:"<<r<<endl;
   //cout<<"列:"<<f<<endl;
   MYSQL_FIELD*field=mysql_fetch_field(res);
   for(int i=0;i<f;i++)
   {
      //cout<<field[i].name<<" ";
      printf("%s",field[i].name);
   }
   cout<<endl;
   for(int i=0;i<r;i++)
   {
      MYSQL_ROW row = mysql_fetch_row(res);
      for(int j=0;j<f;j++)
      {
         printf("%s",row[j]);
      }
      cout<<endl;
   }
   mysql_close(m);
   return 0;
}